﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

using System.ServiceModel;

using CloudPhoneApp2.ServiceReference1;

namespace CloudPhoneApp2
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        protected void button1_Click(object sender, RoutedEventArgs e)
        {
             try
            {
                // create proxy
                Service1Client client = new Service1Client();

                // all web service operation calls from Silverlight have to be asynchronous
                // call method
                client.GetSavingCompleted += new EventHandler<GetSavingCompletedEventArgs>(client_GetSavingCompleted);
                client.GetSavingAsync(ServerCostValue.Text, MaintainanceCostValue.Text, SoftwareCostValue.Text, NoOfServersValue.Text);

                // RESTful calls via WebClient, WebChannelFactory not currently supported
            }
            catch (Exception e1)
            {
                CloudSavings.Text = e1.Message;
            }
        }

        // call back
        void client_GetSavingCompleted(object sender, GetSavingCompletedEventArgs e)
        {
            CloudSavings.Text = e.Result;
            //textBlock1.Text = e.Result;
            //Page1.
        }

        private void NoOfSevers_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if(NoOfServers != null)
            {
                NoOfServersValue.Text = Math.Round(NoOfServers.Value, 0).ToString();
            }            
        }

        private void ServerCost_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if(ServerCost != null)
            {
            ServerCostValue.Text = Math.Round(ServerCost.Value, 0).ToString();
            }
            
        }

        private void MaintainanceCost_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (MaintainanceCost != null)
            {
                MaintainanceCostValue.Text = Math.Round(MaintainanceCost.Value, 0).ToString();
            }
         
        }

        private void SoftwareCost_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (SoftwareCost != null)
            {
                SoftwareCostValue.Text = Math.Round(SoftwareCost.Value, 0).ToString();
            }
        
        }
        
    }
}